<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="xml" version="1.0" encoding="utf-8"
		indent="yes" />

	<xsl:template match="/schemas">
		<xsl:element name="schemas">
			<xsl:element name="schema">
				<xsl:attribute name="name">
				  <xsl:value-of select="/schemas/schema/@name" />
    	        </xsl:attribute>

				<xsl:for-each select="/schemas/schema/sequence">
					<xsl:copy-of select="." />
				</xsl:for-each>

				<xsl:for-each select="/schemas/schema/table">
					<xsl:element name="table">
						<xsl:attribute name="name">
   		                  <xsl:value-of select="@name" />
   		                </xsl:attribute>

						<xsl:variable name="nameTableSchema" select="@name" />

						<xsl:for-each
							select="document('../../input/complementos.xml')/complementos/table">
							<xsl:if test="@name = $nameTableSchema">
								<xsl:copy-of select="*" />   <!-- copia la primary key que faltaba -->
							</xsl:if>
						</xsl:for-each>

						<xsl:copy-of select="*" />  <!-- copia el resto de la tabla -->

					</xsl:element>
				</xsl:for-each>  <!-- fin tabla -->


			</xsl:element> <!-- schema -->
		</xsl:element>  <!-- schemas -->

	</xsl:template>


</xsl:stylesheet>
